package icu.minxin.tree23;

import lombok.Data;

/**
 * @ClassName: Tree23Node
 * @Author AbelEthan
 * @Email AbelEthan@126.com
 * @Date 2021/6/4 下午4:17
 * @Description 23树节点对象
 */
@Data
public class Tree23Node {
    private static final int N = 3;

    /**
     * 节点数据
     */
    private Integer[] data = new Integer[N - 1];
    /**
     * 父节点
     */
    private Tree23Node parentNode;
    /**
     * 子节点
     */
    private Tree23Node[] childrenNodes = new Tree23Node[N];
    /**
     * 节点保存的数据个数
     */
    private Integer count = 0;

    /**
     * 判断是否叶子节点
     *
     * @return
     */
    private boolean isLeaf() {
        return childrenNodes[0] == null;
    }

    /**
     * 判断节点是否存满
     *
     * @return
     */
    private boolean isFull() {
        return count.equals(N - 1);
    }

    /**
     * 将子节点链接
     *
     * @param index
     * @param children
     */
    private void connectChildren(Integer index, Tree23Node children) {
        childrenNodes[index] = children;
        if (children != null) {
            children.parentNode = this;
        }
    }

    /**
     * 删除节点与节点的链接
     *
     * @param index
     * @return
     */
    private Tree23Node disConnectChildren(Integer index) {
        Tree23Node tempNode = childrenNodes[index];
        childrenNodes[index] = null;
        return tempNode;
    }

    /**
     * 获取节点的左右值
     *
     * @param index
     * @return
     */
    private Integer getData(Integer index) {
        return data[index];
    }

    /**
     * 获取某个位置的子树
     *
     * @param index
     * @return
     */
    private Tree23Node getChildren(Integer index) {
        return childrenNodes[index];
    }
}
